﻿var G_DialogBox = new yingsoftDialog('nr', 0);
var G_DialogTextarea = new yingsoftDialog('tb', 1);
var G_DialogContent = new yingsoftDialog('hc', 2);
var G_DialogPop = new yingsoftDialog('pop', 3);

function yingsoftDialog(name, type) {
    var name = name || '';
    var type = type || 0; //0:alert 1:textarea 2:htmlContent
    //是否为ie浏览器
    var IsIE = !!document.all;
    //ie浏览器版本
    var IEVersion = (function () {
        if (!IsIE) return -1;
        try {
            return parseFloat(/msie ([\d\.]+)/i.exec(navigator.userAgent)[1]);
        } catch (e) {
            return -1;
        }
    })();
    //按id获取对象
    var $ = function (Id, isFrame) {
        var o;
        if ("string" == typeof (Id)) o = document.getElementById(Id); else if ("object" == typeof (Id)) o = Id; else return null;
        return isFrame ? (IsIE ? frames[Id] : o.contentWindow) : o;
    }
    //按标签名称获取对象
    //页面的高和宽******************************
    var isStrict = document.compatMode == "CSS1Compat";
    var BodyScale = { x: 0, y: 0, tx: 0, ty: 0 }; //（x，y）：当前的浏览器容器大小  （tx，ty）：总的页面滚动宽度和高度
    var getClientHeight = function () {
//     /*if(IsIE)*/return isStrict ? document.documentElement.clientHeight : document.body.clientHeight; /*else return
//     self.innerHeight;*/
        return  document.getElementsByTagName('html')[0].clientHeight;
    }
    var getScrollHeight = function () {
        var h = !isStrict ? document.body.scrollHeight : document.documentElement.scrollHeight;
        return Math.max(h, getClientHeight());
    }
    var getHeight = function (full) {
        return full ? getScrollHeight() : getClientHeight();
    }
    var getClientWidth = function () { /*if(IsIE)*/
        return isStrict ? document.documentElement.clientWidth : document.body.clientWidth;
        /*else return self.innerWidth;*/
    }
    var getScrollWidth = function () {
        var w = !isStrict ? document.body.scrollWidth : document.documentElement.scrollWidth;
        return Math.max(w, getClientWidth());
    }
    var getWidth = function (full) {
        return full ? getScrollWidth() : getClientWidth();
    }
    var initBodyScale = function () {
        BodyScale.x = getWidth(false);
        BodyScale.y = getHeight(false);
        BodyScale.tx = getWidth(true);
        BodyScale.ty = getHeight(true);
    }
    //页面的高和宽******************************
    // Msg ======================================================================================================================================
    var INFO = 'info';
    var ERROR = 'error';
    var WARNING = 'warning';
    var IsInit = false;
    var timer = null;
    var dvTitle = null;
    var dvCT = null;
    var dvBottom = null;
    var dvBtns = null;
    var lightBox = null;
    var dvMsgBox = null;
    var defaultWidth = '300px';
    var moveProcessbar = function () {
        var o = $(name + 'dvProcessbar'), w = o.style.width;
        if (w == '') w = 20;
        else {
            w = parseInt(w) + 20;
            if (w > 100) w = 0;
        }
        o.style.width = w + '%';
    }
    var InitMsg = function (width) {
        //ie下不按照添加事件的循序来执行，所以要注意在调用alert等方法时要检测是否已经初始化IsInit=true
        var ifStr = '<iframe src="javascript:false" mce_src="javascript:false" style="position:absolute; visibility:inherit; top:0px;left:0px;width:100%; height:100%; z-index:-1;'
                + 'filter=\'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)\';"></iframe>',
            html = '<div class="dialogTop">' +
                '<div class="dialogRight">' +
                '<div class="dialogTitle " id="' + name + 'dvMsgTitle" ></div>' +
                '<div id="' + name + '__close__" style="position:absolute;right:10px;top:10px;color:#fff;cursor:pointer;" class="close-formState"></div>' +
//                            '<i onmousemove="this.style.color = \'#ff0000\'"; onmouseout="this.style.color = \'#ffffff\'"; id="'+ name +'__close__" style="position:absolute;right:10px;top:10px;color:#fff;cursor:pointer;" class="icon-close"></i>' +
                '</div>' +
                '</div>' +
                '<div class="dialogBody">' +
                '<div class="dialogRight">' +
                '<div class="dialogCt" id="' + name + 'dvMsgCT"></div>' +
                '</div>' +
                '</div>' +
                '<div class="dialogBottom" id="' + name + 'dvMsgBottom">' +
                '<div class="dialogRight">' +
                '<div class="dvMsgBtns" id="' + name + 'dvMsgBtns">' +
                '</div>' +
                '</div>';
        dvMsgBox = document.createElement("div");
        dvMsgBox.id = name + "dvMsgBox";
        dvMsgBox.className = 'dvMsgBox';
        dvMsgBox.innerHTML += html;
        document.body.appendChild(dvMsgBox);
        lightBox = document.createElement("div");
        lightBox.id = name + "ShowBolightBox";
        lightBox.className = 'ShowBolightBox';
        document.body.appendChild(lightBox);
        if (IsIE && IEVersion < 7) {//加iframe层修正ie6下无法遮盖住select的问题
            lightBox.innerHTML += ifStr;
            dvMsgBox.innerHTML += ifStr;
        }
        dvBottom = $(name + 'dvMsgBottom');
        dvBtns = $(name + 'dvMsgBtns');
        dvCT = $(name + 'dvMsgCT');
        dvTitle = $(name + 'dvMsgTitle');
        iConClose = $(name + '-close');
        IsInit = true;
    }

    var InitPop = function (width) {
        //ie下不按照添加事件的循序来执行，所以要注意在调用alert等方法时要检测是否已经初始化IsInit=true
        var ifStr = '<iframe src="javascript:false" mce_src="javascript:false" style="position:absolute; visibility:inherit; top:0px;left:0px;width:100%; height:100%; z-index:-1;'
                + 'filter=\'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)\';"></iframe>',
            dvMsgBox = document.createElement("div");
        dvMsgBox.id = name + "dvMsgBox";
        dvMsgBox.className = 'dvMsgBoxPop';
        //        dvMsgBox.innerHTML += html;
        document.body.appendChild(dvMsgBox);
        lightBox = document.createElement("div");
        lightBox.id = name + "ShowBolightBox";
        lightBox.className = 'ShowBolightBox';
        document.body.appendChild(lightBox);
        if (IsIE && IEVersion < 7) {//加iframe层修正ie6下无法遮盖住select的问题
            lightBox.innerHTML += ifStr;
            dvMsgBox.innerHTML += ifStr;
        }
        IsInit = true;
    }

    var InitHtmlContent = function (width, cfg) {
        //ie下不按照添加事件的循序来执行，所以要注意在调用alert等方法时要检测是否已经初始化IsInit=true
        var ifStr = '<iframe src="javascript:false" mce_src="javascript:false" style="position:absolute; visibility:inherit; top:0px;left:0px;width:100%; height:100%; z-index:-1;'
            + 'filter=\'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)\';"></iframe>';
        if (window.location.href.indexOf("/html/") > 0 && (cfg.title !== '切换科目')) {
            html = '<div id="' + name + 'dvMsgBackBtn" style="position:absolute;top:0px;left:0px;font-size:18px;color:#FFF;cursor:pointer;display:none;"></div>' +  //弹窗不用“返回”，去掉<img style="margin-top: 4px;" src="../images/back.png" height="30px" width="30px"><div style="float:right;margin-top:7px;line-height:25px;">返回</div>  陈伟波 2014-10-13
                '<div id="' + name + 'dvMsgClose" style="position:absolute;top:0px;right:0px;font-size:14px;color:#FFF;margin-top:13px;margin-right:9px;cursor:pointer;" class="close-formState">' +
//                        '<i class="icon-close" onmousemove="this.style.color = \'#ff0000\'"; onmouseout="this.style.color = \'#ffffff\'";></i>' +
                '</div>'
                +
                '<div class="dialogTop">' +
                '<div class="dialogRight">' +
                '<div class="dialogTitle2" id="' + name + 'dvMsgTitle">' +
                '<input type="text" placeholder="请输入科目名称" class="search" id="txtKeyWord"/>' +
                '<button class="dialogSeach" id="btnSearchTest">搜索</button>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '<div id="' + name + 'dialogBody" style="margin-top:30px;width:100%;height:100%;overflow-y:auto;overflow-x:hidden;padding-bottom:10px;"></div>';
        }
        else if (cfg.title === '切换科目') {
            if (G_Prg.$('hcdvMsgBox')) {//如果是从科目信息进来切换科目的，就先删除科目信息的内容。
                document.body.removeChild(G_Prg.$('hcdvMsgBox'));
                document.body.removeChild(G_Prg.$('hcShowBolightBox'));
            }
            ;
            html = '<div id="' + name + 'dvMsgBackBtn" style="position:absolute;top:0px;left:0px;font-size:18px;color:#FFF;cursor:pointer;display:none;"></div>' +
                '<div id="' + name + 'dvMsgClose" style="position:absolute;top:0px;right:0px;font-size:14px;color:#FFF;margin-top:11px;margin-right:9px;cursor:pointer;" class="close-formState">' +
//                        '<i class="icon-close" onmousemove="this.style.color = \'#ff0000\'"; onmouseout="this.style.color = \'#ffffff\'";></i>' +
                '</div>' +
                '<div id="2' + name + 'dvMsgClose" style="position:absolute;top:0px;right:0px;font-size:14px;color:#FFF;margin-top:11px;margin-right:44px;cursor:pointer;" class="normal-size">' +
                '</div>'
                +
                '<div class="dialogTop">' +
                '<div class="dialogRight">' +
                '<div class="dialogTitle2" id="' + name + 'dvMsgTitle"></div>' +
                '</div>' +
                '</div>' +
                '<div id="' + name + 'dialogBody" style="margin-top:30px;width:100%;height:100%;overflow-y:auto;overflow-x:hidden;padding-bottom:10px;"></div>';
        } else {
            html = '<div id="' + name + 'dvMsgBackBtn" style="position:absolute;top:0px;left:0px;font-size:18px;color:#FFF;cursor:pointer;display:none;"></div>' +
                '<div id="' + name + 'dvMsgClose" style="position:absolute;top:0px;right:0px;font-size:14px;color:#FFF;margin-top:13px;margin-right:9px;cursor:pointer;" class="close-formState">' +
//                '<i class="icon-close" onmousemove="this.style.color = \'#ff0000\'"; onmouseout="this.style.color = \'#ffffff\'";></i>' +
                '</div>' +
                '<div class="dialogTop">' +
                '<div class="dialogRight">' +
                '<div class="dialogTitle2" id="' + name + 'dvMsgTitle"></div>' +
                '</div>' +
                '</div>' +
                '<div id="' + name + 'dialogBody" style="margin-top:30px;width:100%;height:100%;overflow-y:auto;overflow-x:hidden;padding-bottom:10px;"></div>';
        }

        dvMsgBox = document.createElement("div");
        dvMsgBox.id = name + "dvMsgBox";
        dvMsgBox.className = 'dvMsgBox';
        dvMsgBox.innerHTML += html;
        document.body.appendChild(dvMsgBox);
        lightBox = document.createElement("div");
        lightBox.id = name + "ShowBolightBox";
        lightBox.className = 'ShowBolightBox';
        document.body.appendChild(lightBox);
        if (IsIE && IEVersion < 7) {//加iframe层修正ie6下无法遮盖住select的问题
            lightBox.innerHTML += ifStr;
            dvMsgBox.innerHTML += ifStr;
        }
        dvBottom = $(name + 'dvMsgBottom');
        dvBtns = $(name + 'dvMsgBtns');
        dvCT = $(name + 'dvMsgCT');
        dvTitle = $(name + 'dvMsgTitle');
        IsInit = true;
    }
    var checkDOMLast = function () {//此方法非常关键，要不无法显示弹出窗口。两个对象dvMsgBox和lightBox必须处在body的最后两个节点内
        if (document.body.lastChild != lightBox) {
            document.body.appendChild(dvMsgBox);
            document.body.appendChild(lightBox);
        }
    }
    var createBtn = function (p, v, fn) {
        var btn = document.createElement("input");
        btn.type = "button";
        btn.className = 'btnDialog';
        btn.id = name + '_btn_' + p;
        btn.value = v;
        btn.onmouseover = function () {
            btn.className = 'btnDialogFocus';
        }
        btn.onmouseout = function () {
            btn.className = 'btnDialog';
        }
        btn.onclick = function () {
            hide();

            removeHtmlContentCover();
            removeTextAreaContentCover();
            if (fn) {
                if (type == 1) {
                    //var kk='   '; var _regerBr=new RegExp(' ','gm'); console.log(kk.replace(_regerBr,'').length);
                    var _txt = document.getElementById('dialogTxtArea').value;
                    var _regerSp = new RegExp(' ', 'gm');
                    var resTxt = _txt.replace(_regerSp, '');
                    if (resTxt.length === 0) {
                        _txt = '';
                    }
                    fn(p, _txt);
                } else {
                    fn(p);
                }
            }
        }

        return btn;
        //_closeDialog();
    }
    //黎萍（2015-05-30）增加弹出框的高度
    this.alert = function (msg) {
        this.checkHtmlContent();
        this.checkTextAreaContent();
        this.show({isAlert: true, buttons: { yes: '确认' }, width: '300px', msg: msg, title: '温馨提示' });

    }
    this.confirm = function (msg, fn) {
        this.checkHtmlContent();
        this.checkTextAreaContent();
        //fn为回调函数，参数和show方法的一致
        //this.show({isConfirm: true, buttons: { yes: '确认', no: '取消' }, width: '400px',height:'200px', msg: msg, title: '温馨提示', fn: fn });
        this.show({isConfirm: true, buttons: { yes: '确认', no: '取消' }, width: '400px', msg: msg, title: '温馨提示', fn: fn });
    }
    this.confirmWidth = function (msg, fn, width) {
        this.checkHtmlContent();
        //fn为回调函数，参数和show方法的一致
        this.show({ buttons: { yes: '确认', no: '取消' }, width: width, msg: msg, title: '温馨提示', fn: fn });
    }
    //弹出带文本域的窗口
    this.textarea = function (msg, fn) {
        this.checkHtmlContent();
//        this.checkTextAreaContent();

        this.show({ buttons: { yes: '保存', no: '取消' }, isTextarea: true, width: '800px', height: '500px', text: msg,
            msg: '<textarea id="dialogTxtArea" style="border-radius:0px;width:99%;height:350px;font-size:20px;resize: none; border:1px solid #4093DA;" rows="5" maxlength="150"></textarea>',
            title: '编辑笔记', fn: fn
        });
    }
    //可以内嵌html的容器
    this.htmlContent = function (width, height, title, html, isInnerHtml, fn) {
//        document.body.style.overflow = 'hidden';
        if (name !== 'hc') {
            this.checkHtmlContent();
        }
        this.checkTextAreaContent();
        this.show({ isHtmlContent: true, msg: html, width: width, height: height, title: title, fn: fn, isInnerHtml: isInnerHtml });
        if (name === 'hc') {
            removeHtmlContentCover();
        }
    }

    //气泡弹出框
    this.popMsg = function (msg) {
        this.checkHtmlContent();
        this.checkTextAreaContent();
        this.popShow({ width: '260px', msg: msg });
    }

    this.dispose = function () {
        var _ShowBolightBox = document.getElementById(name + 'ShowBolightBox');
        var _dvMsgBox = document.getElementById(name + 'dvMsgBox');
        document.body.style.overflow = '';
        if (_ShowBolightBox) {
            document.body.removeChild(_ShowBolightBox);
        }
        if (_dvMsgBox) {
            document.body.removeChild(_dvMsgBox);
        }
        if (timer) {
            clearInterval(timer);
            timer = null;
        }
        if (IsIE) window.detachEvent('onresize', onResize);
        else window.removeEventListener('resize', onResize, false);
        removeHtmlContentCover();
        removeTextAreaContentCover();
    }
    var prompt = function (labelWord, defaultValue, txtId, fn) {
        if (!labelWord) labelWord = '请输入：';
        if (!defaultValue) defaultValue = "";
        if (!txtId) txtId = "msg_txtInput";
        this.show({ title: '输入提示', msg: labelWord + '<input type="text" id="' + name + txtId + '" style="width:200px" value="' + defaultValue + '"/>', buttons: { yes: '确认', no: '取消' }, fn: fn });
    }
    var wait = function (msg, title) {
        if (!msg) msg = '正在处理..';
        this.show({ title: title, msg: msg, wait: true });
    }

    var popTimer = null;
    this.popShow = function (cfg) {
        //如果之前没移除，先移除
        if (popTimer) {
            clearTimeout(popTimer);
        }
        var _beforeDvMsgBox = document.getElementById(name + 'dvMsgBox');
        var _beforeLightBox = document.getElementById(name + 'ShowBolightBox');
        if (_beforeLightBox) {
            document.body.removeChild(_beforeLightBox);
        }
        if (_beforeDvMsgBox) {
            document.body.removeChild(_beforeDvMsgBox);
        }
        //cfg:{title:'',msg:'',wait:true,icon:'默认为信息',buttons:{yes:'',no:''},fn:function(btn){回调函数,btn为点击的按钮，可以为yes，no},width:显示层的宽}
        //如果是等待则wait后面的配置不需要了。。
        if (!cfg) throw ("没有指定配置文件！");
        //添加窗体大小改变监听
        if (IsIE) window.attachEvent("onresize", onResize);
        else window.addEventListener("resize", onResize, false);
        //单独处理htmlContent
        if (!IsInit) {
            InitPop(); //初始化dom对象
        } else {
            checkDOMLast(); //检查是否在最后
        }
        //dvMsgBox.id = name + "dvMsgBox";
        dvMsgBox = document.getElementById(name + 'dvMsgBox');
        dvMsgBox.innerHTML = cfg.msg;
        //检查是否要指定宽，默认为300
        if (cfg.width) {
            dvMsgBox.style.width = cfg.width;
        } else {
            dvMsgBox.style.width = defaultWidth;
        }
        //高
        if (cfg.height) {
            dvMsgBox.style.height = cfg.height;
        }
        //可以直接使用show方法停止为进度条的窗口
        if (timer) {
            clearInterval(timer);
            timer = null;
        }

        initBodyScale();
        //绑定背景层点击事件
        lightBox.onclick = function () {
            popDispose();
            clearTimeout(popTimer);
        }
        dvMsgBox.style.display = 'block';
        lightBox.style.display = 'block';
        onResize(false);
        popTimer = setTimeout(function () {
            popDispose();
        }, 3000);

        function popDispose() {
            var _ShowBolightBox = document.getElementById(name + 'ShowBolightBox');
            var _dvMsgBox = document.getElementById(name + 'dvMsgBox');
            if (_ShowBolightBox) {
                document.body.removeChild(_ShowBolightBox);
            }
            if (_dvMsgBox) {
                document.body.removeChild(_dvMsgBox);
            }
            if (timer) {
                clearInterval(timer);
                timer = null;
            }
            if (IsIE) window.detachEvent('onresize', onResize);
            else window.removeEventListener('resize', onResize, false);
        }

    }

    this.show = function (cfg) {

        //cfg:{title:'',msg:'',wait:true,icon:'默认为信息',buttons:{yes:'',no:''},fn:function(btn){回调函数,btn为点击的按钮，可以为yes，no},width:显示层的宽}
        //如果是等待则wait后面的配置不需要了。。
        if (!cfg) throw ("没有指定配置文件！");
        //添加窗体大小改变监听
        if (IsIE) window.attachEvent("onresize", onResize);
        else window.addEventListener("resize", onResize, false);

        //单独处理htmlContent
        if (!IsInit && cfg.isHtmlContent) {
            InitHtmlContent(null, cfg);
        } else if (!IsInit && !cfg.isHtmlContent) {
            InitMsg(); //初始化dom对象
        } else {
            checkDOMLast(); //检查是否在最后
            if (cfg.title === '切换科目' && cfg.isHtmlContent) {
                InitHtmlContent(null, cfg);
            }
        }

        //检查是否要指定宽，默认为300
        if (cfg.width) {
            dvMsgBox.style.width = cfg.width;
        } else {
            dvMsgBox.style.width = defaultWidth;
        }

        //高
        if (cfg.height) {
            dvMsgBox.style.height = cfg.height;
        }
        //可以直接使用show方法停止为进度条的窗口
        if (timer) {
            clearInterval(timer);
            timer = null;
        }
        dvTitle.innerHTML = '';
        //切换科目添加搜索框
        if (cfg.title == '切换科目') {
            dvTitle.style.textAlign = 'left';
            dvTitle.style.marginLeft = '30px';
            dvTitle.innerHTML = '切换科目<input type="text" placeholder="请输入科目名称" class="dialogInput" id="txtKeyWord"/>' +
                '<button class="dialogSeach" id="btnSearchTest">搜索</button>';//cfg.title;
        } else {
            if (cfg.title) dvTitle.innerHTML = cfg.title;
        }
        if (cfg.isConfirm) {
            var _closeIcon = document.getElementById(name + '__close__');
            EventUtil.addHandler(_closeIcon, 'click', function () {
                _closeDialog();
            })
            //_closeIcon.onclick = function () { _closeDialog(); }

        }
        if (cfg.isAlert) {
            var _closeIcon = document.getElementById(name + '__close__');
            EventUtil.addHandler(_closeIcon, 'click', function () {
                _closeDialog();
            })
        }
        if (cfg.isHtmlContent) {
            document.getElementById(name + 'dialogBody').innerHTML = '';
            if (cfg.isInnerHtml) {
                document.getElementById(name + 'dialogBody').innerHTML = cfg.msg;
            } else {
                document.getElementById(name + 'dialogBody').appendChild(cfg.msg);
            }

        } else {
            dvCT.innerHTML = '';
            if (cfg.wait) {
                if (cfg.msg) dvCT.innerHTML = cfg.msg;
                dvCT.innerHTML += '<div class="pro"><div class="bg" id="' + name + 'dvProcessbar"></div></div>';
                dvBtns.innerHTML = '';
                dvBottom.style.height = '10px';
                timer = setInterval(function () {
                    moveProcessbar();
                }, 1000);
            }
            else {
                //if(!cfg.icon)cfg.icon=Msg.INFO;
                if (!cfg.isHtmlContent) {
                    if (!cfg.buttons || (!cfg.buttons.yes && !cfg.buttons.no)) {
                        cfg.buttons = { yes: '确定' };
                    }
                }
                if (cfg.icon) dvCT.innerHTML = '<div class="dialogIcon' + cfg.icon + '"></div>';
                if (cfg.msg) dvCT.innerHTML += cfg.msg + '<div class="dialogClear"></div>';
                var _closeIcon = document.getElementById(name + '__close__');
                EventUtil.addHandler(_closeIcon, 'click', function () {
                    _closeDialog();
                })
                dvBottom.style.height = '70px';
                dvBtns.innerHTML = '<div class="dialogHeight"></div>';
                if (cfg.buttons && cfg.buttons.yes) {
                    dvBtns.appendChild(createBtn('yes', cfg.buttons.yes, cfg.fn));
                    if (cfg.buttons.no) dvBtns.appendChild(document.createTextNode('　'));
                }
                if (cfg.buttons && cfg.buttons.no) dvBtns.appendChild(createBtn('no', cfg.buttons.no, cfg.fn));
            }
        }

        initBodyScale();
        if (cfg.isTextarea) {
            document.getElementById('dialogTxtArea').value = cfg.text;
        }
        if (cfg.isHtmlContent) {
            var _close = document.getElementById(name + 'dvMsgClose');
            var _enlarge = document.getElementById('2' + name + 'dvMsgClose');
            if (cfg.title == '测试得分') {
                _close.style.marginTop = 5 + 'px';
            }
            var _back = document.getElementById(name + 'dvMsgBackBtn');
            // _closeIcon = document.getElementById(name + '-close');

            _close.onclick = function () {
                _closeDialog();
            }
            _enlarge && (_enlarge.onclick = function () {
                _enlargeDialog();
            })
            _back.onclick = function () {
                _closeDialog();
            }
            //_closeIcon.onclick = function () { _closeDialog(); }


            function _enlargeDialog() {
                var iTag = _enlarge.getElementsByTagName('i')[0];
                var hcdvMsgBox = document.getElementById('hcdvMsgBox');
//                var liArry=G_Prg.$('Chapter').getElementsByTagName('li');
//                var liWidth='';
                if (_enlarge.className === 'normal-size') {
                    _enlarge.className = 'bigger-size';
                    hcdvMsgBox.style.width = document.body.clientWidth + 'px';
                    hcdvMsgBox.style.height = document.body.clientHeight + 'px';
                    hcdvMsgBox.style.left = '0px';
                    hcdvMsgBox.style.top = '0px';

                    if (document.getElementById('four').style.display === 'block') {//如果是住院医师
                        G_Prg.$('Chapter').style.maxHeight = document.body.clientHeight - 40 - document.getElementById('four').offsetHeight + 'px';
                    } else {
                        G_Prg.$('Chapter').style.maxHeight = '740px';
                    }
//                  liWidth='490px';//不懂为什么这里不能用jquery

                } else {
                    _enlarge.className = 'normal-size';
                    hcdvMsgBox.style.width = '800px';
                    hcdvMsgBox.style.height = '583px';
//                   hcdvMsgBox.style.left='319px';

                    hcdvMsgBox.style.left = (document.body.clientWidth - 800) / 2 + 'px';
//                   hcdvMsgBox.style.top='115px';
                    hcdvMsgBox.style.top = (document.body.clientHeight - 583) / 2 + 'px';

                    if (document.getElementById('four').style.display === 'block') {
                        G_Prg.$('Chapter').style.maxHeight = 583 - 40 - document.getElementById('four').offsetHeight + 'px';
                    } else {
                        G_Prg.$('Chapter').style.maxHeight = '500px';
                    }
//                  liWidth='290px';

                }
//                for(var i=0;i<liArry.length;i++){
////                    liArry[i].style.width=liWidth;
//                }
            }
        }

        dvMsgBox.style.display = 'block';
        lightBox.style.display = 'block';

        if (type === 2) {
            setTimeout(function () {
                var cardPY = document.getElementById('cardPY');
                if (document.getElementById(name + 'dialogBody')) {

                    if (cardPY) {
                        document.getElementById(name + 'dialogBody').style.height = (document.getElementById(name + 'dvMsgBox').clientHeight - 15 - cardPY.clientHeight + 5) + 'px';
                    } else {
                        document.getElementById(name + 'dialogBody').style.height = (document.getElementById(name + 'dvMsgBox').clientHeight - 50) + 'px';
                    }
                }
            }, 0);
        }

        onResize(false);
        function _closeDialog() {
            if (dvMsgBox) {
                if (dvMsgBox.removeNode) {
                    //var div_video = dvMsgBox.getElementById('div_Video');
//                    if(CKobject._K_('div_Video')){
//                        CKobject._K_('div_Video').innerHTML = '';
//                    }
                    /*if (CKobject.getObjectById('ckplayer_a1')) {
                        if (document.getElementById('pageVideo')) {
                            CKobject.getObjectById('ckplayer_a1').newAddress('html5-&gt;http://up.ksbao.com/jinyingjie/jpkc/hgfhjgf/1-kaoshidagang.MP4');
                            //document.getElementById('pageVideo').innerHTML = CKobject.getObjectById('ckplayer_a1')._V_.outerHTML;
                        }
                    }*/
                    dvMsgBox.removeNode(true);
                } else {
//                    if(CKobject._K_('div_Video')){
//                        CKobject._K_('div_Video').innerHTML = '';
//                    }
                    /*if (CKobject.getObjectById('ckplayer_a1')) {
                        if (document.getElementById('pageVideo')) {
                            CKobject.getObjectById('ckplayer_a1').newAddress('html5-&gt;http://up.ksbao.com/jinyingjie/jpkc/hgfhjgf/1-kaoshidagang.MP4');
                            //document.getElementById('pageVideo').innerHTML = CKobject.getObjectById('ckplayer_a1')._V_.outerHTML;
                        }
                    }*/
                    dvMsgBox.remove();
                }

            }
            if (lightBox) {
                if (lightBox.removeNode) {
                    lightBox.removeNode(true);
                } else {
                    lightBox.remove();
                }

            }
            if (timer) {
                clearInterval(timer);
                timer = null;
            }
            if (IsIE) window.detachEvent('onresize', onResize);
            else window.removeEventListener('resize', onResize, false);
            IsInit = false;
            if (cfg.fn) {
                cfg.fn();
            }
            document.body.style.overflow = 'auto';
            removeHtmlContentCover();
            removeTextAreaContentCover();

        }

        var _enterTriggerSure = {//弹窗的时候除了回车键、ESC，其他键都禁用，并且回车键触发确定按钮！(2015-6-20周江)
            init: function () {
                this.btnEvent('nr_btn_yes');
                this.btnEvent('nr_btn_no');
                this.btnFoucs('#nr_btn_yes');
                this.closeEvent();
                this.enterEvent();

            },
            btnFoucs: function (id) {
                if (jQuery('#nr_btn_no').length !== 0) {//如果有取消按钮，让确定按钮获得焦点
                    jQuery('#nr_btn_yes').css('background-color', '#00a1e9');
                    jQuery('#nr_btn_no').css('background-color', '#00a1e9');
                    jQuery(id).css('background-color', '#31b4ed');
                    jQuery(id).focus();
//去除谷歌下，buttion获得焦点默认的边框
                    document.getElementById('nr_btn_yes').style.outline='none';
                    document.getElementById('nr_btn_no').style.outline='none';

                    if (id === '#nr_btn_yes') {
                        jQuery('#nr_btn_no').css('background-color', '');
                    } else {
                        jQuery('#nr_btn_yes').css('background-color', '');
                    }
                }
            },
            btnEvent: function (id) {
                var self = this;
                var ele = document.getElementById(id)
                if (ele) {
                    var old = ele.onclick;
                    ele.onclick = function () {
                        old();
                        if (jQuery('.ShowBolightBox:visible').length === 0) {
                            document.onkeydown = self.keyDown;
                        }
                    }
                }
            },
            closeEvent: function () {
                var self = this;
                var oldClose = _closeDialog;
                _closeDialog = function () {
                    oldClose();
                    if (jQuery('.ShowBolightBox:visible').length === 0) {
                        document.onkeydown = self.keyDown;
                    }
                    _closeDialog = oldClose;
                }
            },
            enterEvent: function () {
                var self = this;
                document.onkeydown = function (event) {
                    if (!(jQuery('#nrdvMsgBox').css('display') === 'block')&&(!jQuery('#searchDoneTest2'))) {
                        document.onkeydown = self.keyDown;
                    } else {
                        var e = event || window.event || arguments.callee.caller.arguments[0];//兼容浏览器的event
                        var keyCode = e.keyCode || e.which || e.charCode;
                        if (keyCode === 13) {
                            if(jQuery('#searchDoneTest2')){
                                jQuery('#searchDoneTest2').trigger('click');
                            }else{
//                                jQuery('#' + document.activeElement.id).trigger('click');
                                //发现其实获得焦点的按钮默认会获得回车触发点击事件，不用自己触发
                            }

                        } else if (keyCode === 27) {
                            if (jQuery('#nr_btn_no').length !== 0) {
                                jQuery('#nr_btn_no').trigger('click');
                            } else {
                                _closeDialog();
                            }

                        } else if (keyCode === 37) {
                            self.btnFoucs('#nr_btn_yes');
                        } else if (keyCode === 39) {
                            self.btnFoucs('#nr_btn_no');
                        }
                    }
                }
            },
            keyDown: function (event) {
                var e = event || window.event || arguments.callee.caller.arguments[0];//兼容浏览器的event
                var keyCode = e.keyCode || e.which || e.charCode;
                //阻止默认事件的执行，不然 按上下键的时候屏幕会滚动！
                if (keyCode === 37 || keyCode === 38) {
                    if (e.preventDefault) {
                        e.preventDefault();
                    } else {
                        window.event.returnValue = false;
                    }

                    jQuery('#movePre').trigger("click");//触发“上一题”按钮
                } else if (keyCode === 39 || keyCode === 40) {
                    //阻止默认事件的执行，不然 按上下键的时候屏幕会滚动！
                    if (e.preventDefault) {
                        e.preventDefault();
                    } else {
                        window.event.returnValue = false;
                    }
                    jQuery('#moveNext').trigger("click");//触发“下一题”按钮
                } else if (keyCode >= 65 && keyCode <= 90) {
                    var index = keyCode - 65 + 1;//选项li的 下标（从1开始）
                    jQuery('.exam:visible ul').find(':nth-child(' + index + ')').trigger("click");
                    //.exam:visible ul选出可见的class=exam的div的子节点ul
                    //find(':nth-child(index)')选出 第index 个选项！
                }else if (keyCode === 50) {

                    jQuery('#calBtn').trigger("click");
                } else if (keyCode === 51) {
                    jQuery('#helpBtn').trigger("click");
                } else if (keyCode === 52) {
                    jQuery('#marking').trigger("click");
                }
            }

        }
        _enterTriggerSure.init();
    }
    var hide = function () {
        dvMsgBox.style.display = 'none';
        lightBox.style.display = 'none';
//        document.body.removeChild(dvMsgBox);
//        document.body.removeChild(lightBox);
        if (timer) {
            clearInterval(timer);
            timer = null;
        }
        if (IsIE) window.detachEvent('onresize', onResize);
        else window.removeEventListener('resize', onResize, false);
    }

//    function _closeDialog() {
//        document.body.removeChild(dvMsgBox);
//        document.body.removeChild(lightBox);
//        if (timer) { clearInterval(timer); timer = null; }
//        if (IsIE) window.detachEvent('onresize', onResize);
//        else window.removeEventListener('resize', onResize, false);
//        IsInit = false;
//        //if (cfg.fn) { cfg.fn(); }
//        document.body.style.overflow = 'auto';
//        removeHtmlContentCover();
//        removeTextAreaContentCover();
//    }

    var lightBoxClick = function (event) {
        event = event ? event : window.event;
        event.stopPropagation();
    }

    this.checkHtmlContent = function () {
        var htmlContentDIV = document.getElementById('hcdvMsgBox');
        if (htmlContentDIV) {
            //遮罩
            var hcCover = document.createElement('div');
            hcCover.id = 'tempHtmlContentCover';
            hcCover.style.position = 'fixed';
            /*hcCover.style.top = htmlContentDIV.style.top;
             hcCover.style.left = htmlContentDIV.style.left;
             hcCover.style.width = (htmlContentDIV.clientWidth + 2)+'px';
             hcCover.style.height = (htmlContentDIV.clientHeight + 2)+'px';*/
            hcCover.style.top = 0 + 'px';
            hcCover.style.left = 0 + 'px';
            hcCover.style.width = '100%';
            hcCover.style.height = '100%';
            hcCover.style.backgroundColor = '#000000';
            hcCover.style.opacity = 0.4;
            hcCover.style.filter = 'alpha(opacity=40)';
            if (!document.getElementById('tempHtmlContentCover')) {
                htmlContentDIV.appendChild(hcCover);
            }
        }
    }

    this.checkTextAreaContent = function () {
        var htmlContentDIV = document.getElementById('tbdvMsgBox');
        if (htmlContentDIV) {
            //遮罩
            var hcCover = document.createElement('div');
            hcCover.id = 'tempTextAreaContentCover';
            hcCover.style.position = 'fixed';
            /*hcCover.style.top = htmlContentDIV.style.top;
             hcCover.style.left = htmlContentDIV.style.left;
             hcCover.style.width = (htmlContentDIV.clientWidth + 2)+'px';
             hcCover.style.height = (htmlContentDIV.clientHeight + 2)+'px';*/
            hcCover.style.top = 0 + 'px';
            hcCover.style.left = 0 + 'px';
            hcCover.style.width = '100%';
            hcCover.style.height = '100%';
            hcCover.style.backgroundColor = '#000000';
            hcCover.style.opacity = 0.4;
            hcCover.style.filter = 'alpha(opacity=40)';
            if (!document.getElementById('tempTextAreaContentCover')) {
                htmlContentDIV.appendChild(hcCover);
            }
        }
    }

    var removeTextAreaContentCover = function () {
        var htmlContentCover = document.getElementById('tempTextAreaContentCover');
        if (htmlContentCover) {
            var father = htmlContentCover.parentNode;
            father.removeChild(htmlContentCover);
        }
    }

    var removeHtmlContentCover = function () {
        var htmlContentCover = document.getElementById('tempHtmlContentCover');
        if (htmlContentCover) {
            var father = htmlContentCover.parentNode;
//            father.innerHTML = '';
            father.removeChild(htmlContentCover);
        }
    }

    var onResize = function (isResize) {
        if (isResize) initBodyScale();
        lightBox.style.width = BodyScale.tx + 'px';
        lightBox.style.height = BodyScale.ty + 'px';
        var mathTop = Math.floor((BodyScale.y - dvMsgBox.offsetHeight) / 2);
        var mathLeft = Math.floor((BodyScale.x - dvMsgBox.offsetWidth) / 2);
        dvMsgBox.style.top = mathTop >= 0 ? mathTop + 'px' : '0px';
        dvMsgBox.style.left = mathLeft >= 0 ? mathLeft + 'px' : '0px';

        lightBox.style.width = window.document.body.clientWidth + 'px';
        lightBox.style.height = window.document.body.clientHeight + 'px';
        if (document.getElementById(name + 'ShowBolightBox')) {
            document.getElementById(name + 'ShowBolightBox').style.width = window.document.body.clientWidth + 'px';
            document.getElementById(name + 'ShowBolightBox').style.height = document.getElementsByTagName('html')[0].clientHeight + 'px';
        }


        if (type === 1) {
            var bgDiv = document.getElementById('tbShowBolightBox');
            if (bgDiv) {
                bgDiv.style.width = (window.document.body.clientWidth + 1) + 'px';
                bgDiv.style.height = (document.getElementsByTagName('html')[0].clientHeight) + 'px';
            }

        }
        /*
         EventUtil.addHandler(window, 'resize', function () {

         /* htmlContentDIV = document.getElementById('hcdvMsgBox');
         if(htmlContentDIV){
         //遮罩
         var hcCover = document.createElement('div');
         hcCover.id = 'tempHtmlContentCover';
         hcCover.style.position = 'fixed';
         hcCover.style.top = htmlContentDIV.style.top;
         hcCover.style.left = htmlContentDIV.style.left;
         hcCover.style.width = (htmlContentDIV.clientWidth + 2)+'px';
         hcCover.style.height = (htmlContentDIV.clientHeight + 2)+'px';
         hcCover.style.backgroundColor = '#000000';
         hcCover.style.opacity = 0.4;
         if (!document.getElementById('tempHtmlContentCover')) {
         htmlContentDIV.appendChild(hcCover);
         }
         }


         var htmlContentDIV = document.getElementById('tbdvMsgBox');
         if(htmlContentDIV){
         //遮罩
         var hcCover = document.createElement('div');
         hcCover.id = 'tempTextAreaContentCover';
         hcCover.style.position = 'fixed';
         hcCover.style.top = htmlContentDIV.style.top;
         hcCover.style.left = htmlContentDIV.style.left;
         hcCover.style.width = (htmlContentDIV.clientWidth + 2)+'px';
         hcCover.style.height = (htmlContentDIV.clientHeight + 2)+'px';
         hcCover.style.backgroundColor = '#000000';
         hcCover.style.opacity = 0.4;
         if (!document.getElementById('tempTextAreaContentCover')) {
         htmlContentDIV.appendChild(hcCover);
         }
         }


         */

        //填坑用的遮罩当遇到窗体大小改变是重新计算宽高和坐标/*
        /*
         var htmlContentCover = document.getElementById('tempHtmlContentCover');
         if(htmlContentDIV){
         htmlContentDIV = htmlContentCover.parentNode;
         htmlContentCover.style.top = htmlContentDIV.style.top;
         htmlContentCover.style.left = htmlContentDIV.style.left;
         htmlContentCover.style.width = (htmlContentDIV.clientWidth + 2)+'px';
         htmlContentCover.style.height = (htmlContentDIV.clientHeight + 2)+'px';
         }

         var htmlContentCover = document.getElementById('tempTextAreaContentCover');
         if(htmlContentCover){
         htmlContentDIV = htmlContentCover.parentNode;
         htmlContentCover.style.top = htmlContentDIV.style.top;
         htmlContentCover.style.left = htmlContentDIV.style.left;
         htmlContentCover.style.width = (htmlContentDIV.clientWidth + 2)+'px';
         htmlContentCover.style.height = (htmlContentDIV.clientHeight + 2)+'px';
         }


         });*/
    }
    // 跨浏览器事件处理对象，填坑用，韦捷 2014-10-21
    var EventUtil = {
        addHandler: function (elem, type, handler) {
            if (elem.addEventListener) {
                elem.addEventListener(type, handler, false);
            } else if (elem.attachEvent) {
                elem.attachEvent('on' + type, handler);
            } else {
                var oldEvent = elem['on' + type];
                if (typeof oldEvent != 'function') {
                    elem['on' + type] = handler;
                } else {
                    elem['on' + type] = function () {
                        oldEvent();
                        handler();
                    }
                }
            }
        },
        removeHandler: function (elem, type, handler) {
            if (elem.removeEventListener) {
                elem.removeEventListener(type, handler, false);
            } else if (elem.detachEvent) {
                elem.detachEvent('on' + type, handler);
            } else {
                elem['on' + type] = null;
            }
        }
    }
}
